import random
import string


def generate_random_string(length, include_upper=True, include_lower=True, include_digits=True, include_special=False,
                           special_chars='', include_chinese=False, exclude_chars=''):
    characters = ''
    if include_upper:
        characters += string.ascii_uppercase
    if include_lower:
        characters += string.ascii_lowercase
    if include_digits:
        characters += string.digits
    if include_special:
        characters += special_chars
    if include_chinese:
        characters += '你我他她它们'

    # 移除排除字符
    for char in exclude_chars:
        characters = characters.replace(char, '')

    random_string = ''.join(random.choice(characters) for _ in range(length))
    return random_string


def generate_text_file(filename, content):
    with open(filename, 'w') as file:
        file.write(content)


# 示例用法

length = 50  # 字符串长度
include_upper = True  # 是否包含大写字母
include_lower = True  # 是否包含小写字母
include_digits = True  # 是否包含数字
include_special = False  # 是否包含特殊字符
special_chars = '!@#$%^&*()'  # 包含的特殊字符 !@#$%^&*() 输入为空则不包含特殊字符
include_chinese = False  # 是否包含汉字 False
exclude_chars = 'abc'  # 排除的字符 输入为空则不排除任何字符
output_filename = '../filesOutput/length.txt'  # 输出文件名

# 可能需要 pip install random-string

random_string = generate_random_string(length, include_upper, include_lower, include_digits, include_special,
                                       special_chars, include_chinese, exclude_chars)
generate_text_file(output_filename, random_string)
print(f"生成的随机字符串已保存到{output_filename}文件中。")
